package com.ylkj.wx.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ylkj.common.base.BaseDaoHibernate;
import com.ylkj.wx.dao.BizInfoDAO;
import com.ylkj.wx.dto.BizInfoDTO;
import com.ylkj.wx.entitis.BizInfoEntity;

@Repository
public class BizInfoDAOImpl extends BaseDaoHibernate implements BizInfoDAO {

	@Override
	public List<BizInfoDTO> findBizInfoList(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BizInfoDTO fineOneBizInfoById(String bizCode) {
		String sql = " SELECT id AS id ,biz_name,biz_code ,biz_phone,address AS address FROM biz_info WHERE biz_code = ? ";
		Query query = this.getSession().createSQLQuery(sql);
         query.setParameter(0, bizCode);
         List<Object[]> list = query.list();
         if(list!=null && list.size()>0){
        	 Object[] object = list.get(0);
        	 BizInfoDTO dto = new BizInfoDTO();
        	 dto.setId((Integer) object[0]);
        	 dto.setBizName(object[1]==null?"":(String)object[1]);
        	
        	 dto.setBizCode( object[2]==null?"":object[2].toString());
        	 dto.setBizPhone(object[3]==null?"":(String)object[3]);
        	 dto.setAddress(object[4]==null?"":(String)object[4]);
        	 return dto;
         }
		return null;
	}

	@Override
	public BizInfoEntity fineOneBizInfoByCode(String bizCode) {
		String hql="from BizInfoEntity where bizCode=?";
		List<BizInfoEntity> bizList= this.getHibernateTemplate().find(hql, bizCode);
		if(bizList==null||bizList.isEmpty()){
			return null;
		}
		return bizList.get(0);
	}

}
